package com.infore.eureka;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Discription TODO
 * @Autor lijianhua
 * @Date 2020/2/19 11:26
 */
@EnableEurekaServer
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class EurekaApplication extends SpringBootServletInitializer implements CommandLineRunner {
    protected static Log log = LogFactory.getLog(EurekaApplication.class);
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(EurekaApplication.class);
    }

    public static void main(String[] args)  throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(EurekaApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        log.info("\n----------------------------------------------------------\n" +
                "Application service is running! Access URLs:\n" +
                "Eureka Service地址: \t http://" + ip + ":" + port + "\n" +
                "----------------------------------------------------------");
    }

    @Override
    public void run(String... args) throws Exception {
        System.out.println("-------------Eureka service started successfully----------------");
    }
}
